package tp.pr5.gui;

import java.awt.FlowLayout;
import javax.swing.JLabel;
import tp.pr5.Directions;
import tp.pr5.GameObserver;
import tp.pr5.MapObserver;
import tp.pr5.MensajesConst;
import tp.pr5.PlayerObserver;
import tp.pr5.RoomInfo;
import tp.pr5.items.ItemList;


public class InfoPanel extends javax.swing.JPanel implements GameObserver,
		MapObserver, PlayerObserver {
	
	private static final long serialVersionUID = 1L;
	private JLabel infoLabel;
	private String _currentText="";
	private String _oldText="";
	@SuppressWarnings("unused")
	private String _old_old_Text="";
	public InfoPanel() {
		super();
		FlowLayout PanelLabelLayout = new FlowLayout();
		this.setLayout(PanelLabelLayout);
		{
			infoLabel = new JLabel();
			
			this.add(infoLabel);
			this.updateText("The game is starting now");
		}
	}

	@Override public void inventoryUpdate(ItemList inventory)
	{
		this.updateText(
				"The inventory now contains "+ inventory.size() + " elements");
		
	}

	@Override public void itemEmpty(String itemName)
	{
		this.updateText(itemName);
		
	}

	@Override public void itemLooked(String description)
	{
		this.updateText(description);
		
	}

	@Override public void itemUsed(String itemName)
	{
		this.updateText(itemName);
		
	}

	@Override public void playerDead()
	{
		this.updateText(MensajesConst.muerto);
		
	}

	@Override public void playerLookedInventory(ItemList inventory)
	{
		this.updateText("You are looking your inventory");
		
	}

	@Override public void playerUpdate(int newHealth, int newScore)
	{

		this.updateText("Player atributes has been updated ("
				+ newHealth + "," + newScore+")");
		
	}

	@Override public void playerHasExaminedRoom(RoomInfo r)
	{
		//TODO
		
	}

	@Override public void roomEntered(Directions direction, RoomInfo targetRoom)
	{
		this.updateText("...moving to " + direction);
		
	}

	@Override public void gameError(String msg)
	{
		this.updateText(msg);
		
	}

	@Override public void gameHelp()
	{
		// TODO Auto-generated method stub
		System.out.println(MensajesConst.hHelp);
		
	}

	@Override public void gameOver(boolean win)
	{
		if (!win) {		
			this.updateText(MensajesConst.muerto);
		}
		if (win){
			this.updateText(MensajesConst.salidamsg);

		}
		
	}

	@Override public void gameQuit()
	{
		System.exit(0);
		
	}

	@Override public void gameStart(RoomInfo initialRoom, int playerPoints,
			int playerHealth)
	{
		this.updateText("Game starts");
		
		
	}
private void updateText(String newText) {
	this._old_old_Text=this._oldText;
	this._oldText=this._currentText;
	this._currentText=newText;
	this.infoLabel.setText(this._currentText); //this._old_old_Text+" | "+this._oldText+" | "+
}
	

}